package com.jlboot.model.po.sys;

import com.jfinal.kit.JsonKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.jlboot.core.consts.Consts;
import com.jlboot.core.util.LoginUtil;

import java.util.Date;

/**
 * @author wangsanfei
 * @version 1.0
 * Create by 2024/1/29 21:17
 */
public class SysDeleteLog extends Model<SysDeleteLog> {

    public static final SysDeleteLog dao=new SysDeleteLog();
    public static final String table="sys_delete_log";

    public static String getNextId(){
        return SysIdGenerator.dao.getNextId(table);
    }

    public SysDeleteLog setCommon(){
        Date now=new Date();
        this.set("id",SysIdGenerator.dao.getNextId(table));
        this.set("del_tag", Consts.COMMON_NONE_DEL);
        this.set("create_time",now);
        this.set("update_time",now);
        this.set("create_by", LoginUtil.getUserId());
        this.set("update_by",LoginUtil.getUserId());
        return this;
    }

    public void addDeleteLog(String table_name,Object data){
        Record delete_log=new Record();
        delete_log.set("id",SysIdGenerator.dao.getNextId(table));
        delete_log.set("del_tag", Consts.COMMON_NONE_DEL);
        delete_log.set("create_time",new Date());
        delete_log.set("update_time",new Date());
        delete_log.set("create_by", LoginUtil.getUserId());
        delete_log.set("update_by",LoginUtil.getUserId());
        delete_log.set("table",table_name);
        delete_log.set("content", JsonKit.toJson(data));
        Db.save(table,delete_log);
    }

}
